distutils で Tkinter を要求するにはどうすればよいですか? (How do I require Tkinter with distutils?)


問題の説明

distutils で Tkinter を要求するにはどうすればよいですか? (How do I require Tkinter with distutils?)

distutils を使用してプログラムをコンパイルしようとしていますが、パッケージをインストールする前に、ユーザーが Tkinter をインストールしていることを確認したいと考えています。

私の Google 検索では、有用な情報や、これを行う方法の手がかりを見つけてください。

ありがとう、ウェイン


リファレンスソリューション

方法 1:

You can have a class that inherits from install and then do this:

from distutils.command.install import install

class Install(install):
    def run(self):
        if not check_dependencies():
             # Tkinter was not installed, handle this here
        install.run(self) # proceed with the installation

def check_dependencies():
    try:
        return __import__('Tkinter')
    except ImportError:
        return None

方法 2:

Unfortunately there is no standard cross‑platform way to force Tkinter to be installed. Tkinter is part of the Python standard library so distributors who strip out Tkinter, or other standard library modules, and package them as optional entities are doing so using their own package management tools and, in general, you'd need to know the specific commands for each distribution. The best you can do in general is test for and fail gracefully if Tkinter (or tkinter in Python 3) is not importable, so something like:

import sys
try:
    import Tkinter
except ImportError:
    sys.exit("Tkinter not found")

方法 3:

Tkinter is in the python standard library, it should always be there.

(by Wayne Werneruser225312Ned DeilyAlex)

リファレンスドキュメント

  1. How do I require Tkinter with distutils? (CC BY‑SA 3.0/4.0)

#tkinter #Python #distutils






関連する質問

機能を停止するにはどうすればよいですか? (How do I stop a function?)

Python Tkinter コードでボタンが機能しない (buttons not working in Python Tkinter code)

Tkinter/ttk をテーマにしたメッセージ ボックス? (Tkinter/ttk themed Message Box?)

tkinterボタンをクリックしてスレッドを開始し、GUIがフリーズするのを防ぎます (tkinter Button click to start thread to prevent GUI from freezing)

distutils で Tkinter を要求するにはどうすればよいですか? (How do I require Tkinter with distutils?)

カウントダウンが重ならないようにするにはどうすればよいですか? (How do I stop the countdown from overlapping one another?)

.after を使用して Tkinter でキャンバス テキストを表示および非表示にする方法 (How to Make Canvas Text Appear and Disappear in Tkinter Using .after)

tkinter を使用してキーボードのキーに関数をキーバインドするにはどうすればよいですか (How do I keybind functions to keys in the keyboard with tkinter)

Python tkinter キャンバス アニメーション (Python tkinter canvas animation)

Tkinter で tag_add の問題を解決するにはどうすればよいですか (How can I resolve problem with tag_add in Tkinter)

tkinter 、after、callback の予期しない動作 (tkinter , unexpected behaviour of after,callback)

Tkinter Scale の ttk Style レイアウトの要素を変更する (Change element in ttk Style layout of Tkinter Scale)







コメント